<template>
	
	<CommonPageByDevice 
	ref="commonPageByDeviceRef"
	navTitle="智能POS管理"
	 searchTitle="搜索设备名称、编号" 
	 searchType="device" 
	 :searchParams="{deviceType: 4}"
	 :bottomBtnTitle="ak.ent.has('ENT_DEVICE_AUTO_POS_ADD') ? '绑定设备' : null "
	 @bottomBtnClickFunc="bottomBtnClickFunc"
	 :reqTableDataFunc="reqTableDataFunc"
	  >
	</CommonPageByDevice>
	
	 <JSinglePopup ref="jsinglePopupRef" :list="codeBindList" activeColor="#FF5B4C" />
</template>

<script setup>
import { reactive, ref } from 'vue'
import { onReachBottom, onUnload } from '@dcloudio/uni-app'
import emit from '@/commons/utils/emit.js'
import CommonPageByDevice from '../commons/CommonPageByDevice.vue'
import { reqLoad, API_URL_SYS_DEVICE_LIST } from '@/http/apiManager.js'
import go from '@/commons/utils/go.js'
import DeviceCommonsRender from '@/pages/list/render/DeviceCommonsRender.vue'
import ak from '@/commons/utils/ak.js'

const jsinglePopupRef = ref(null)

const commonPageByDeviceRef = ref()

// 监听 更新事件 
onUnload( () => uni.$off(emit.ENAME_REF_AUTOPOS_LIST) )
uni.$on(emit.ENAME_REF_AUTOPOS_LIST, function(data){
	commonPageByDeviceRef.value.refTable(true)
})


const reqTableDataFunc = (params) => {
	params.deviceType = 4 // 1-云喇叭, 2-云打印, 3-扫码pos, 4-智能pos, 5-收银插件
  return reqLoad.list(API_URL_SYS_DEVICE_LIST, params)
}

function bottomBtnClickFunc(){
	jsinglePopupRef.value.open()
}


const codeBindList = [
  { label: '扫码绑定', value: 'scanCode', fun: () => {
	  uni.scanCode().then(({ result }) => {
	    go.to('PAGES_APP_POS_BIND', { deviceNo: result })
	  })
	}
  },
  { label: '手动绑定', value: 'handBind', fun: () => {
      go.to('PAGES_APP_POS_BIND')
    }
  },
]


onReachBottom(() => {})
</script>

<style lang="scss" scoped>

</style>
